#include <vector>
#include <iostream>
#include <iomanip>
#include "NewtonInterpolation.h"
// #include <matplotlibcpp.h>
using namespace std;

/*
namespace plt = matplotlibcpp;

void predictWeights(const vector<double>& days, const vector<double>& weights, const string& label) {
    vector<double> predictedDays, predictedWeights;
    double step = 0.1; // 步长

    // 生成预测曲线的点
    for (double day = 0; day <= 28; day += step) { 
        predictedDays.push_back(day);
        predictedWeights.push_back(newtonInterpolation(days, weights, day));
    }

    // 绘制预测曲线
    plt::named_plot(label, predictedDays, predictedWeights, "r-");
}
*/

int main() {
    cout << "Problem E is running." << endl;
    vector<double> days = {0, 6, 10, 13, 17, 20, 28};
    vector<double> sp1 = {6.67, 17.3, 42.7, 37.3, 30.1, 29.3, 28.7};
    vector<double> sp2 = {6.67, 16.1, 18.9, 15.0, 10.6, 9.44, 8.89};

    /*
    predictWeights(days, sp1, "Sp1");
    predictWeights(days, sp2, "Sp2");

    // 设置图表的标题和标签
    plt::title("Predicted Weight Curves of Larvae");
    plt::xlabel("Days after birth");
    plt::ylabel("Average weight");
    plt::legend();
    plt::grid(true);

    // 显示图表
    plt::show();
    */
    
    // 预测额外15天后的体重
    double extraDays = 15;
    vector<double> futureDays = {28 + extraDays};
    double predictedWeightSp1 = newtonInterpolation(days, sp1, 28 + extraDays);
    double predictedWeightSp2 = newtonInterpolation(days, sp2, 28 + extraDays);

    cout << "Predicted weight of Sp1 after " << extraDays << " more days: " << predictedWeightSp1 << endl;
    cout << "Predicted weight of Sp2 after " << extraDays << " more days: " << predictedWeightSp2 << endl;

    // 判断是否会死亡
    bool willDieSp1 = predictedWeightSp1 <= 0;
    bool willDieSp2 = predictedWeightSp2 <= 0;

    cout << "Will Sp1 die? " << (willDieSp1 ? "Yes" : "No") << endl;
    cout << "Will Sp2 die? " << (willDieSp2 ? "Yes" : "No") << endl;

    return 0;
}
